package com.portal.controller;

import com.portal.exception.Assert;
import com.portal.model.vo.AddressVo;
import com.portal.model.vo.CartVo;
import com.portal.result.impl.BusinessCode;
import com.portal.service.AddressService;
import com.portal.service.CartService;
import com.portal.util.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/address")
@Tag(name = "地址管理")
@Slf4j
public class AddressController {

    @Autowired
    private AddressService addressService;
    @Autowired
    private JwtUtil jwtUtil;


    @GetMapping("/findAddress")
    @Operation(summary = "根据用户id查询收货地址")
    public ResponseEntity findAddress(@RequestHeader("Authorization") String token) {
        String userId = jwtUtil.getValue(token, "userId");
        List<AddressVo> addressVoList = addressService.findAddressByUserId(Long.parseLong(userId));
        return ResponseEntity.ok(addressVoList);
    }
}